package com.qf.ssm.controller;

import com.qf.ssm.common.request.CartRequestParams;
import com.qf.ssm.common.request.OrderRequestParams;
import com.qf.ssm.common.vo.ResponseCartMoney;
import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Order;
import com.qf.ssm.entity.Product;
import com.qf.ssm.service.CartAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86155
 * @ClassName: com.qf.ssm.controller.CartAppController
 * @Description: 该类的功能描述
 * @date: 2021/10/12 20:14
 */
@RestController
@RequestMapping("/cart")
public class CartAppController {
    @Resource
    private CartAppService cartAppService;

    /**
     * 添加商品到购物车
     *
     * @param cartRequestParams
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody CartRequestParams cartRequestParams) {
        Boolean isAdd = cartAppService.add(cartRequestParams);
        return ResponseResult.success(isAdd);
    }

    /**
     * 删除购物车商品
     *
     * @param ids
     * @param memberId
     * @return
     */
    @PostMapping("/del/batch/")
    public ResponseResult<Boolean> batchDel(@RequestParam List<Long> ids, @RequestParam Long memberId) {
        Integer isDelete = cartAppService.batchDel(ids, memberId);
        return ResponseResult.success(isDelete == ids.size());
    }

    /**
     * 计算购物车商品总原价价格和优惠后的价格
     *
     * @param memberId
     * @return
     */
    @PostMapping("/money")
    public ResponseResult<ResponseCartMoney> cartMoney(@RequestParam Long memberId) {
        ResponseCartMoney cartMoney = cartAppService.cartMoney(memberId);
        return ResponseResult.success(cartMoney);
    }

    /**
     * 订单结算    先展示勾选的商品--计算要付款的金额--创建订单
     *
     * @param orderRequestParams
     * @return
     */
    @PostMapping("/count")
    public ResponseResult<Boolean> creatOrder(@RequestBody OrderRequestParams orderRequestParams) {
        Boolean isCreat = cartAppService.creatOrder(orderRequestParams);
        return ResponseResult.success(isCreat);
    }


}
